package com.sds.session.manager.vo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.Cookie;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sds.session.manager.SessionMasterInfo;

public class UserInfo {
	private Logger logger = LoggerFactory.getLogger(SessionMasterInfo.class);
	private String userId;
	private String userIP;
	private List<Domain> domains; 
	public UserInfo(String userId, String userIP, String domainName, Cookie[] cookie) {
		this.userId = userId;
		this.userIP = userIP;
		Domain domain = new Domain(domainName, cookie);
		domains = new ArrayList<Domain>();
		domains.add(domain);
	}
	
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getUserIP() {
		return userIP;
	}
	public void setUserIp(String userIP) {
		this.userIP = userIP;
	}
	public List<Domain> getDomains() {
		return domains;
	}
	public void setDomains(List<Domain> domains) {
		this.domains = domains;
	}
	public boolean isRegisteredDomain(String domainName) {
		for(Domain domain : domains) {
			if(domain.getName().equals(domainName)) {
				return true;
			}
		}
		return false;
	}
	public void addDomain(String domainName, Cookie[] cookie) {
		if(!isRegisteredDomain(domainName)) {
			Domain domain = new Domain(domainName, cookie);
			domains.add(domain);
		}
	}
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		sb.append("["+userId+"|"+userIP+"] - [");
		for(Domain domain : domains) {
			sb.append(domain);
		}
		sb.append("]");
		return sb.toString();
	}
	public void debug() {
		for(Domain domain : domains) {
			logger.debug("["+userId+"|"+userIP+"] - [" + domain + "]");
		}
	}
}
